package com.jjx.trainingapi.service.impl;

import com.jjx.trainingapi.entity.po.DcCourse;
import com.jjx.trainingapi.entity.po.QuestionItem;
import com.jjx.trainingapi.entity.po.UserRecordError;
import com.jjx.trainingapi.util.LoginManager;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jjx.trainingapi.mapper.UserRecordFavoriteMapper;
import com.jjx.trainingapi.entity.po.UserRecordFavorite;
import com.jjx.trainingapi.service.UserRecordFavoriteService;

/**
 * @author LoveHuahua
 * @date 2022年05月24日 1:10
 * @description believe in yourself
 */
@Service
public class UserRecordFavoriteServiceImpl extends ServiceImpl<UserRecordFavoriteMapper, UserRecordFavorite> implements UserRecordFavoriteService {

    /**
     * 添加收藏
     *
     * @param param
     */
    @Override
    public void addFavoriteQuestion(UserRecordError param) {
        UserRecordFavorite one = lambdaQuery().eq(UserRecordFavorite::getUserId, LoginManager.getUserId()).eq(UserRecordFavorite::getQuestionItemId, param.getQuestionItemId()).one();
        if (one == null){
            UserRecordFavorite entity = new UserRecordFavorite();
            entity.setUserId(LoginManager.getUserId());
            entity.setQuestionItemId(param.getQuestionItemId());
            save(entity);
        }
    }

    /**
     * 检测是否点赞
     *
     * @param param
     * @return
     */
    @Override
    public boolean checkFavoriteQuestion(UserRecordError param) {
        return lambdaQuery().eq(UserRecordFavorite::getUserId,LoginManager.getUserId())
                .eq(UserRecordFavorite::getQuestionItemId,param.getQuestionItemId()).count() != 0;
    }

    /**
     * 收藏列表
     *
     * @param param
     * @return
     */
    @Override
    public List<QuestionItem> favoriteQuestionList(DcCourse param) {
        return baseMapper.favoriteQuestionList(param,LoginManager.getUserId());
    }
}

